﻿@{
    ViewBag.Title = "Index";

    
}
        <script type="text/javascript">
            $(document).ready(function () {
                var filter = '';
                var order = 'ExId desc';
                ResetExList();
                $.getJSON("/QuizService.svc/Categories?$filter=ParentId%20eq%20null", function (result) {
                    //$("#catList").empty();
                    $.each(result.d, function (i, item) {
                        $("#catList").append('<h3><a href="#" class="catLink" data-id="' + item.CatId + '">' + item.CatName + '</a></h3><div id="childList' + item.CatId + '">Loading...</div>').accordion('destroy').accordion({
                            active: false,
                            collapsible: true,
                            autoHeight: false,
                            navigation: true,
                            disabled: true
                        });
                    });
                });
                $(".catLink").live("click", function () {
                    var link = $(this);
                    $.getJSON("/QuizService.svc/Categories?$filter=ParentId%20eq%20" + link.attr("data-id"), function (result) {
                        $("#childList" + link.attr("data-id")).empty();
                        $.each(result.d, function (i, item) {
                            $("#childList" + link.attr("data-id")).append('<div><input type="radio" class="childRadio" name="childRadio" id="childRadio' + item.CatId + '" value="' + item.CatId + '" /><label for="childRadio' + item.CatId + '">' + item.CatName + '</label></div>');
                        });
                    });
                });
                $(".childRadio").live("click", function () {
                    filter = "CatId eq " + $(this).val();
                    ResetExList();
                });
                $("#filterByCatid").change(function () {
                    if ($(this).is(':checked')) {
                        $("#catList").accordion("enable");
                    } else {
                        $("#catList").accordion("disable");
                        filter = '';
                        ResetExList();
                    }
                });

                $(":radio[name=orderBy]").change(function () {
                    order = $(this).val() + ' ' + $(":radio[name=orderSort]:checked").val();
                    ResetExList();
                });

                $(":radio[name=orderSort]").change(function () {
                    order = $(":radio[name=orderBy]:checked").val() + ' ' + $(this).val();
                    ResetExList();
                });

                function ResetExList() {
                    $("#exList").text('Loading...');
                    var uri = "/QuizService.svc/Exercises?$filter=" + filter + "&$orderby=" + order;
                    $.getJSON(uri, function (result) {
                        $("#exList").empty();
                        $.each(result.d, function (i, item) {
                            $("#exList").append('<div><a href="/Quiz/TestInfo/' + item.ExId + '">' + item.ExName + '</a></div>');
                        });
                    });
                }
            })
        </script>
        <div id="container">
            <h2><a href="/Quiz/Create">@ESN.Languages.LangString.Load("create", "Quiz")</a></h2>
            <div style="float: left; width: 27%;">
                <div>@ESN.Languages.LangString.Load("filter_cat", "Quiz") <input type="checkbox" id="filterByCatid" /></div>
                <div id="catList"></div>
            </div>
            <div style="float: right; width : 70%; border: 1px solid;">
                <table>
                    <tbody>
                        <tr>
                            <td>
                                <input type="radio" name="orderBy" id="ExId" value="ExId" checked="checked" /> <label for="ExId">@ESN.Languages.LangString.Load("filter_create_time", "Quiz")</label>
                            </td>
                            <td>
                                <input type="radio" name="orderBy" id="ExTime" value="ExTime" /> <label for="ExTime">@ESN.Languages.LangString.Load("filter_time", "Quiz")</label>
                            </td>
                            <td>
                                <input type="radio" name="orderBy" id="ExDone" value="ExDone" /> <label for="ExDone">@ESN.Languages.LangString.Load("filter_done", "Quiz")</label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="radio" name="orderBy" id="ExAveragePoint" value="ExAveragePoint" /> <label for="ExAveragePoint">@ESN.Languages.LangString.Load("filter_avg_point", "Quiz")</label>
                            </td>
                            <td>
                                <input type="radio" name="orderBy" id="ExShot" value="ExShot" /> <label for="ExShot">@ESN.Languages.LangString.Load("filter_num_shot", "Quiz")</label>
                            </td>
                            <td>
                                <input type="radio" name="orderBy" id="ExNumQues" value="ExNumQues" /> <label for="ExNumQues">@ESN.Languages.LangString.Load("filter_num_quest", "Quiz")</label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="radio" name="orderBy" id="ExAverageTime" value="ExAverageTime" /> <label for="ExAverageTime">@ESN.Languages.LangString.Load("filter_avg_time", "Quiz")</label>
                            </td>
                            <td>
                                 <input type="radio" name="orderSort" id="desc" value="desc" checked="checked" /> <label for="desc">@ESN.Languages.LangString.Load("filter_desc", "Quiz")</label> 
                            </td>
                            <td>
                                <input type="radio" name="orderSort" id="asc" value="asc" /> <label for="asc">@ESN.Languages.LangString.Load("filter_asc", "Quiz")</label>
                            </td>
                        </tr>
                    </tbody>
                </table>
                <br />
                <hr />
                <div id="exList"><img width="300" height="43" src="/Content/images/loading.gif" alt="loading..." /></div>
            </div>
        </div>
